library(ggmap) # NOTE: you need to set up an API key to use Google Mapsm <-get_googlemap(center =c(-74.435018, 40.521089), zoom =17, maptype ="hybrid")ggmap(m, extent ="device")
We have 5 big tasks today, so please follow along closely.
Class resources
In general, you will only need your own computer(s) for this class. However, you also have access to the following spaces:
Classroom B266
The class schedule is posted outside the room or online.
You may use the room when no class is scheduled (before 4PM).
Lab space B235
All students in this class have access to this lab (use RU ID).
The lab is available for use at any time.
All computers in both rooms are all set. The only step you may need is to install the required R packages.
Class resources
Once you are comfortable with Git/GitHub, you can:
simply show up and work directly on a lab computer,
push your work to GitHub when finished,
and later pull everything onto your own computer(s).
I personally really enjoy this part. It feels like two versions of you are working in parallel spaces.
Today, we will meet Git/GitHub, your future best friend for not losing work!
History of R
R is a relatively young language:
1992: Robert Gentleman and Ross Ihaka started to develop R as a research project.
1995: Convinced by Martin Maechler, R became open-source under GPL2 license.
1997 - 2000: A critical stage for early development, including R core group, CRAN, and r-project.org.
2000: R 1.0.0 was released at February 29.
R system
R system
Let’s get back to this code chunk:
# Load librarieslibrary(terra) # library is a function from base R# Query DEM data for Colombia# elevation_30s is a function from R package geodatacol_dem <- geodata::elevation_30s(country ="COL", res =10, path =tempdir())# Plot the map to a png file# plot is a special function, which we call as generic function in R.plot(col_dem, axes =FALSE, box =FALSE)
RStudio
It is an Integrated Development Environment (IDE). It was originally designed for R, but now also supports others, such as Python.
An IDE acts like a “smart home” for coding. For example:
R is the language (like English, Chinese, Spanish, etc).
RStudio is like the Google Doc or Microsoft Word.
Let’s take a quick look at R and RStudio to get a better sense of them.
Your R package!
Let’s work together to create your first-ever R package for this class.
Set up a working directory, e.g.
c:\My Documents\courses (Windows)
/Users/you/courses (macOS).
Make sure you remember where it is.
Install R package devtools:
Run install.packages("devtools") in Console
Or install it from Packages tab in RStudio.
Type 1 in the Chat if you’ve done these two steps.
Your R package!
Create an R package (let me show you first)
Type 2 in the Chat if you’ve created the package.
Version control
Git and local environment
Version control is the idea, and Git is the actual machine to do it.
git add: you pick the good parts and put them in a staging area.
git commit: you snap the photo and file it away.
Fun time
git add and git commit your updates on your own package.
Type 3 in the Chat if you’ve done!
Fun time
Let’s make some changes to the package DESCRIPTION:
Package: ls320
Type: Package
Title: What the Package Does (Title Case)
Version: 0.1.0
Authors@R: c(
person(
"Jane", "Doe",
email = "jane@example.com",
role = c("aut", "cre")
)
)
Description: More about what it does (maybe more than one line).
Continuation lines should be indented.
Replace the entireAuthors@R lines with two new lines:
Author: Your Name
Maintainer: Your Name <your.email@domain.com>
Update Title and Description.
then git add and git commit your changes
Type 4 in the Chat if you’ve done!
Git and GitHub
The package on your local machine is the local repo
GitHub is the remote repo
Remote repo on GitHub
You should have already set up your GitHub account and SSH.
Go to either your personal GitHub account or SSELP
It is easier for me to monitor your work if you create the repo under SSELP
But the choice is entirely up to you.
Create a new private repo (let me show you first)
Link local repo to remote repo on GitHub
Run what you have been told on GitHub
Run git push origin main in terminal or hit the Push button in Git tab.
Type 5 in the Chat if you can see everything on your remote repo!
Invite me and Arafat as the collaborator for your repo (!!)
Only after you do this, will we be able to access your repo.
Class notes (Highly recommended)
You can create a folder, for example, named as “docs” or “notes” within your class package.
Organize all your class notes in this folder using R Markdown.
R Markdown
One of the many benefits of using RStudio is that it makes writing R Markdown convenient. But why R Markdown?
Has an accessible learning curve (rich text syntax)
Integrate R code directly into writing
Reproducibility!
Offers many output formats (HTML, PDF, Word, etc.)
R Markdown
R Markdown
Syntax
Let’s run a demo together to learn the syntax (if have time).